home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / misc1 / iv26_w30.zip / INTERVIE / SENSOR.H < prev    next >
C/C++ Source or Header  |  1992-02-19  |  3KB  |  96 lines

  1. /*
  2.  * Copyright (c) 1987, 1988, 1989 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, distribute, and sell this software and its
  5.  * documentation for any purpose is hereby granted without fee, provided
  6.  * that the above copyright notice appear in all copies and that both that
  7.  * copyright notice and this permission notice appear in supporting
  8.  * documentation, and that the name of Stanford not be used in advertising or
  9.  * publicity pertaining to distribution of the software without specific,
  10.  * written prior permission.  Stanford makes no representations about
  11.  * the suitability of this software for any purpose.  It is provided "as is"
  12.  * without express or implied warranty.
  13.  *
  14.  * STANFORD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  18.  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  19.  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  20.  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  21.  */
  22.  
  23. /*
  24.  * Sensors describe input events of interest.
  25.  */
  26.  
  27. #ifndef sensor_h
  28. #define sensor_h
  29.  
  30. #include <InterViews/event.h>
  31. #include <InterViews/resource.h>
  32.  
  33. const int initmask       = 0x0000;
  34. const int motionmask     = 0x0001;
  35. const int keymask        = 0x0002;
  36. const int entermask     = 0x0004;
  37. const int leavemask     = 0x0008;
  38. const int focusmask     = 0x0010;
  39. const int substructmask = 0x0020;
  40. const int upmask        = 0x0040;
  41. const int downmask      = 0x0080;
  42.  
  43. class Sensor : public Resource {
  44. public:
  45.     Sensor();
  46.     Sensor(Sensor*);
  47.     ~Sensor();
  48.  
  49.     void Catch(EventType);
  50.     void CatchButton(EventType, int);
  51.     void CatchChannel(int);
  52.     void CatchTimer(int, int);
  53.     void Ignore(EventType);
  54.     void IgnoreButton(EventType, int);
  55.     void IgnoreChannel(int);
  56.     void CatchRemote();
  57.     void IgnoreRemote();
  58.     virtual boolean Interesting(Event&);
  59.  
  60. protected:
  61.     unsigned mask;
  62.     unsigned int down[16];
  63.     unsigned int up[16];
  64.     unsigned channels;
  65.     int maxchannel;
  66.     boolean timer;
  67.     long clkticks;
  68.     int sec, usec;
  69.  
  70.     int ButtonIndex (unsigned b) { return (b >> 4) & 07; }
  71.     unsigned int ButtonFlag (unsigned b) { return 1 << (b & 0xf); }
  72.     void SetButton (unsigned int a[], unsigned b) {
  73.     a[ButtonIndex(b)] |= ButtonFlag(b);
  74.     }
  75.     void ClearButton (unsigned int a[], unsigned b) {
  76.     a[ButtonIndex(b)] &= ~ButtonFlag(b);
  77.     }
  78.     boolean ButtonIsSet (unsigned int a[], unsigned b) {
  79.     return (a[ButtonIndex(b)] & ButtonFlag(b)) != 0;
  80.     }
  81.     void SetMouseButtons (unsigned int a[]) { a[0] |= 0x7; }
  82.     void ClearMouseButtons (unsigned int a[]) { a[0] &= ~0x7; }
  83.     boolean MouseButtons (unsigned int a[]) { return (a[0] & 0x7) != 0; }
  84.  
  85. private:
  86.     friend class Interactor;
  87.     friend class Scene;
  88. };
  89.  
  90. extern Sensor* allEvents;
  91. extern Sensor* onoffEvents;
  92. extern Sensor* updownEvents;
  93. extern Sensor* noEvents;
  94.  
  95. #endif
  96.